<template>
  <div class="">
    <el-table border height="350" v-loading="loading" :data="dataList">
      <el-table-column
        label="房间名称"
        align="center"
        min-width="100"
        prop="name"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        label="总量(kwh)"
        align="center"
        min-width="120"
        prop="year"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.year | numDealfilters }}
        </template>
      </el-table-column>
      <el-table-column
        prop="month1"
        label="一月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month1 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month2"
        label="二月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month2 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month3"
        label="三月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month3 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month4"
        label="四月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month4 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month5"
        label="五月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month5 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month6"
        label="六月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month6 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month7"
        label="七月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month7 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month8"
        label="八月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month8 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month9"
        label="九月(kwh)"
        show-overflow-tooltip
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month9 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month10"
        label="十月(kwh)"
        show-overflow-tooltip
        align="center"
        width="110"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month10 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month11"
        label="十一月(kwh)"
        show-overflow-tooltip
        align="center"
        width="110"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month11 | numDealfilters }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="month12"
        label="十二月(kwh)"
        show-overflow-tooltip
        align="center"
        width="110"
      >
        <template slot-scope="scope">
          <div>{{ scope.row.month12 | numDealfilters }}</div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getRoomsummary } from "@/api/general/index.js";
import { dealElectricity } from "@/utils";
export default {
  filters: {
    numDealfilters(num) {
      if (null != num) {
        return dealElectricity(num, 1, 2);
      } else {
        return "";
      }
    },
  },
  components: {},
  props: {
    year: {
      type: [String, Number],
      default: 2024,
    },
  },
  data() {
    return {
      dataList: [],
      loading: false,
    };
  },
  created() {},
  mounted() {},
  watch: {
    year: {
      handler(val) {
        if (val) {
          this.requestRoomlist();
        }
      },
      deep: false,
      immediate: true,
    },
  },
  methods: {
    // 房间统计
    requestRoomlist() {
      this.loading = true;
      let query = {
        year: this.year,
        // pageSize: 1,
      };
      // query.deptIds = [this.$store.state.user.deptId];
      getRoomsummary(query)
        .then((res) => {
          this.loading = false;
          if (res.code === 700) {
            this.$message.warning(res.msg);
            return false;
          }
          console.log(res, "requestRoomlist");
          this.dataList = res?.data ?? [];
        })
        .catch(() => {
          // this.$message.error("系统错误,请联系管理员!");
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
